package sz.szsmk.citizencard.mvp.presenter;

import android.util.Log;

import com.google.gson.Gson;

import javax.inject.Inject;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.CollectStandReq;
import sz.szsmk.citizencard.model.network.bean.request.QueryStandLinesReq;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.QueryStandLinesRes;
import sz.szsmk.citizencard.mvp.contract.IBusSiteDetailContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.ui.activity.IMainActivity;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/6 15:52
 * description:
 */
public class BusSiteDetailPresenter extends IBasePresenter
        implements IBusSiteDetailContact.IBusSiteDetailPresenter<IBusSiteDetailContact.IBusSiteDetailView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public BusSiteDetailPresenter(GsdxNetApi gsdxNetApi) {
        this.mNetworkDateSource = NetworkDateSources.getInstance();
        this.gsdxNetApi = gsdxNetApi;
    }

    @Override
    public void getSearchList(String stand_code, String stand_guid) {
        QueryStandLinesReq standLinesReq = new QueryStandLinesReq();
        standLinesReq.setStand_name(stand_code);
        standLinesReq.setStand_guid(stand_code);
        standLinesReq.setUserID("string");
        String json = new Gson().toJson(standLinesReq);
        Log.d("clark",json);
        mNetworkDateSource.queryStandLines(standLinesReq, new SubscribeResult<QueryStandLinesRes>() {
            @Override
            protected void onOk(QueryStandLinesRes response) {
                String json1 = new Gson().toJson(response);
                ((IBusSiteDetailContact.IBusSiteDetailView) mView).getSearchListSucc(response);
            }

            @Override
            protected void onFailure(QueryStandLinesRes response) {
                super.onFailure(response);
                ((IBusSiteDetailContact.IBusSiteDetailView) mView).getSearchListFail(response);
            }


        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });


    }

    @Override
    public void collectStand(String stand_guid, String stand_name) {
        CollectStandReq collectStandReq = new CollectStandReq();
        collectStandReq.setStand_guid(stand_guid);
        collectStandReq.setStand_name(stand_name);
        collectStandReq.setUserID("string");
        String json = new Gson().toJson(collectStandReq);
        mNetworkDateSource.collectStand(collectStandReq, new SubscribeResult<BaseBean>() {
            @Override
            protected void onOk(BaseBean response) {
                ((IBusSiteDetailContact.IBusSiteDetailView) mView).collectStandSucc(response);
            }

            @Override
            protected void onFailure(BaseBean response) {
                super.onFailure(response);
                ((IBusSiteDetailContact.IBusSiteDetailView) mView).collectStandFail(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });

    }

    @Override
    public void cancelCollectStand(String stand_guid, String stand_name) {
        CollectStandReq collectStandReq = new CollectStandReq();
        collectStandReq.setStand_guid(stand_guid);
        collectStandReq.setStand_name(stand_name);
        collectStandReq.setUserID("string");
        String json = new Gson().toJson(collectStandReq);
        mNetworkDateSource.cancelCollectStand(collectStandReq, new SubscribeResult<BaseBean>() {
            @Override
            protected void onOk(BaseBean response) {
                ((IBusSiteDetailContact.IBusSiteDetailView) mView).cancelCollectStandSucc(response);
            }

            @Override
            protected void onFailure(BaseBean response) {
                super.onFailure(response);
                ((IBusSiteDetailContact.IBusSiteDetailView) mView).cancelCollectStandFail(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }
}
